package com.oreilly.ez.fileserver.web;

import com.oreilly.ez.fileserver.base.R;
import com.oreilly.ez.fileserver.entity.SysUser;
import com.oreilly.ez.fileserver.service.ISysUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@CrossOrigin
@RestController
@RequestMapping("/sysUsers")
public class SysUserCtrl extends BaseCtrl<SysUser> {

    @Autowired
    private ISysUserService sysUserService;

    @Override
    Object find(SysUser sysUser, @PageableDefault Pageable pageable) throws Exception {
        return sysUserService.find(sysUser, pageable);
    }

    @Override
    Object findById(@PathVariable String id) throws Exception {
        SysUser sysUser = sysUserService.findById(id);
        return R.ok(sysUser);
    }

    @Override
    Object add(@RequestBody  SysUser sysUser) throws Exception {
         sysUserService.add(sysUser);
         return R.ok(sysUser);
    }

    @Override
    Object update(@RequestBody SysUser sysUser) throws Exception {
        sysUserService.update(sysUser);
        return R.ok(sysUser);
    }

    @Override
    Object delete(String[] ids) throws Exception {
        sysUserService.deleteByIds(ids);
        return R.ok("delete ok");
    }
}
